﻿using picFilter.App_Code;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace picFilter.Controllers
{
    public class resourceController : ApiController
    {
        // GET api/resource/5
        /// <summary>
        /// 获取并显示指定图片
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public HttpResponseMessage Get(int id)
        {
            DataTable dt = DBHelper.ExecuteDataTable("select fileData From pic Where id=" + id);
            byte[] img = new byte[0];
            if (dt.Rows.Count>0 && !dt.Rows[0]["FILEDATA"].Equals(""))
            {
                img = (byte[])dt.Rows[0]["FILEDATA"];
            }
            
            var resp = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content=new ByteArrayContent(img)
            };
            resp.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpg");
            return resp;
        }

    }
}
